package com.yantong.result;


import com.yantong.constant.BusinessCode;
import io.swagger.annotations.ApiModel;

import java.util.HashMap;
import java.util.Map;

/**
 * @author kanghaixin
 */
public class ResultVo extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public ResultVo() {
		put("code", 0);
		put("msg", "操作成功");
	}

	public static ResultVo error() {
		return error(1, "操作失败");
	}

	public static ResultVo error(String msg) {
		return error(500, msg);
	}

	public static ResultVo error(int code, String msg) {
		ResultVo r = new ResultVo();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static ResultVo error(BusinessCode businessCode) {
		ResultVo r = new ResultVo();
		r.put("code", businessCode.getCode());
		r.put("msg", businessCode.getMsg());
		return r;
	}

	public static ResultVo ok(String msg) {
		ResultVo r = new ResultVo();
		r.put("msg", msg);
		return r;
	}

	public static ResultVo ok(Map<String, Object> map) {
		ResultVo r = new ResultVo();
		r.putAll(map);
		return r;
	}

	public static ResultVo ok() {
		return new ResultVo();
	}

	@Override
	public ResultVo put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
